//
//  MTSetPasswordViewController.m
//  ShiShiBang
//
//  Created by 宋宝强 on 16/9/18.
//  Copyright © 2016年 motianjituan. All rights reserved.
//

#import "MTSetPasswordViewController.h"

#import "MTHttpTools.h"
#import "MTLoginViewController.h"

@interface MTSetPasswordViewController ()
@property (weak, nonatomic) IBOutlet UITextField *setpwdField;
@property (weak, nonatomic) IBOutlet UITextField *verifiCodeField;

@end

@implementation MTSetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
- (IBAction)backClick:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
- (IBAction)loginClick:(id)sender {
    if (self.setpwdField.text != self.verifiCodeField.text) {
        [MBProgressHUD showError:@"密码输入不一致，请重新输入"];
        return;
    }
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[@"mobile"] = [NSString stringWithFormat:@"%lu",self.numberPhone];
    dict[@"password"] = [NSString stringWithFormat:@"%@",self.setpwdField.text];
    
     NSLog(@"%@",dict);

    [MTHttpTools post:@"http://120.76.242.81:8080/ssb-app/user/register.do" params:dict success:^(id responseObj) {
        
           [MBProgressHUD showSuccess:@"注册成功" toView:self.view ];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            MTLoginViewController *vc = [[MTLoginViewController alloc] init];
            [self presentViewController:vc animated:YES completion:nil];
        });
      

    } failure:^(NSError *error) {
       [MBProgressHUD showError:@"注册失败" toView:self.view];

    }];
}

//监听键盘高度
- (void)keyboardWasShown:(NSNotification*)aNotification
{
    //键盘高度
    [UIView animateWithDuration:0.1 animations:^{
        self.view.transform = CGAffineTransformMakeTranslation(0, -100);
    }];
}

-(void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    [UIView animateWithDuration:0.1 animations:^{
        self.view.transform = CGAffineTransformMakeTranslation(0, 0);
    }];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [UIView animateWithDuration:0.3 animations:^{
        [self.view endEditing:YES];
    }];
}

@end
